/*    */ package com.zimbra.cs.service.account;
/*    */ 
/*    */ import com.zimbra.common.account.Key.AccountBy;
/*    */ import com.zimbra.common.account.Key.IdentityBy;
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.common.soap.AccountConstants;
/*    */ import com.zimbra.common.soap.Element;
/*    */ import com.zimbra.cs.account.Account;
/*    */ import com.zimbra.cs.account.AccountServiceException;
/*    */ import com.zimbra.cs.account.Identity;
/*    */ import com.zimbra.cs.account.Provisioning;
/*    */ import com.zimbra.soap.DocumentHandler;
/*    */ import com.zimbra.soap.ZimbraSoapContext;
/*    */ import java.util.Iterator;
/*    */ import java.util.Map;
/*    */ import java.util.Set;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class ModifyIdentity
/*    */   extends DocumentHandler
/*    */ {
/*    */   public Element handle(Element request, Map<String, Object> context)
/*    */     throws ServiceException
/*    */   {
/* 38 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/* 39 */     Account account = getRequestedAccount(zsc);
/* 40 */     Identity identity = null;
/*    */     
/* 42 */     if (!canModifyOptions(zsc, account)) {
/* 43 */       throw ServiceException.PERM_DENIED("can not modify options");
/*    */     }
/* 45 */     Provisioning prov = Provisioning.getInstance();
/*    */     
/* 47 */     Element eIdentity = request.getElement("identity");
/* 48 */     Map<String, Object> attrs = AccountService.getAttrs(eIdentity, "name");
/*    */     
/*    */ 
/* 51 */     for (Iterator<String> it = attrs.keySet().iterator(); it.hasNext();) {
/* 52 */       if (!((String)it.next()).toLowerCase().startsWith("zimbrapref"))
/* 53 */         it.remove();
/*    */     }
/* 55 */     String id = eIdentity.getAttribute("id", null);
/* 56 */     String key; if (id != null) { String key;
/* 57 */       identity = prov.get(account, Key.IdentityBy.id, key = id);
/*    */     } else {
/* 59 */       identity = prov.get(account, Key.IdentityBy.name, key = eIdentity.getAttribute("name"));
/*    */     }
/*    */     
/* 62 */     if (identity == null) {
/* 63 */       String[] childIds = account.getChildAccount();
/* 64 */       for (String childId : childIds) {
/* 65 */         Account childAccount = prov.get(Key.AccountBy.id, childId, zsc.getAuthToken());
/* 66 */         if (childAccount != null) {
/*    */           Identity childIdentity;
/*    */           Identity childIdentity;
/* 69 */           if (id != null) {
/* 70 */             childIdentity = prov.get(childAccount, Key.IdentityBy.id, key = id);
/*    */           } else {
/* 72 */             childIdentity = prov.get(childAccount, Key.IdentityBy.name, key = eIdentity.getAttribute("name"));
/*    */           }
/*    */           
/* 75 */           if (childIdentity != null) {
/* 76 */             identity = childIdentity;
/* 77 */             account = childAccount;
/* 78 */             break;
/*    */           }
/*    */         }
/*    */       }
/*    */     }
/*    */     
/* 84 */     if (identity == null) {
/* 85 */       throw AccountServiceException.NO_SUCH_IDENTITY(key);
/*    */     }
/* 87 */     prov.modifyIdentity(account, identity.getName(), attrs);
/*    */     
/* 89 */     Element response = zsc.createElement(AccountConstants.MODIFY_IDENTITY_RESPONSE);
/* 90 */     return response;
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/account/ModifyIdentity.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */